package com.tizona.system;


import com.tizona.TarifdConfig;
import com.tizona.dao.jdbc.FastStatement;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.Hashtable;

// Referenced classes of package com.tizona.system:
//            ParameterNotFoundException, TarifdConfig, SQLRequest, FastStatement

public class TVPackage
{

    TVPackage(String s, TarifdConfig tarifdconfig)
        throws SQLException
    {
        _id = s;
        _cfg = tarifdconfig;
        try
        {
            fstmtPARAM = tarifdconfig.sql.prepare("SELECT VALUE from TV_PACK_PROPS where TCP_ID=" + _id + " and NAME=? and not(SDATE>?) and not(EDATE<?)");
            fstmtCODE = tarifdconfig.sql.prepare("SELECT TPK_CODE from TV_PACK where TCP_ID=" + _id);
            fstmtNAME = tarifdconfig.sql.prepare("SELECT TPK_NAME from TV_PACK where TCP_ID=" + _id);
        }
        catch(SQLException sqlexception)
        {
            System.out.println(sqlexception.getMessage());
        }
        _params = new Hashtable();
    }

    public String getID()
    {
        return _id;
    }

    public String getCode()
        throws SQLException
    {
        if(_code == null)
        {
            _res = fstmtCODE.query();
            _code = _res.getString(1);
        }
        return _code;
    }

    public String getName()
        throws SQLException
    {
        if(_name == null)
        {
            _res = fstmtNAME.query();
            _name = _res.getString(1);
        }
        return _name;
    }

    public String getParameter(String s, Date date)
        throws ParameterNotFoundException
    {
        String s1 = (String)_params.get(s);
        if(s1 == null)
            try
            {
                fstmtPARAM.setString(1, s);
                fstmtPARAM.setString(2, date.toString());
                fstmtPARAM.setString(3, date.toString());
                _res = fstmtPARAM.query();
                s1 = _res.getString(1);
                if(s1 == null)
                    throw new ParameterNotFoundException("name");
            }
            catch(SQLException sqlexception)
            {
                System.out.println(sqlexception.getMessage());
            }
        return s1;
    }

    FastStatement fstmtPARAM;
    FastStatement fstmtCODE;
    FastStatement fstmtNAME;
    private String _id;
    private String _code;
    private String _name;
    private Hashtable _params;
    private TarifdConfig _cfg;
    private ResultSet _res;
}
